package com.service.impl;

import com.dao.Td_punishedDao;
import com.entity.Td_punished;
import com.service.inte.PunishedServiceInte;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PunishedServiceImpl implements PunishedServiceInte {

    @Autowired
    private Td_punishedDao td_punishedDao;

    @Transactional
    @Override
    public int save(Td_punished td_punished) {
        try {
            td_punishedDao.save(td_punished);
            return 1;
        }catch (Exception e){
            return 0;
        }
    }

    @Override
    public List<Object[]> getByName(String name, int page){
        return td_punishedDao.getByName("%"+name+"%",new PageRequest(page,10));
    }

    @Override
    public int memberPunishCount(int loginId) {
        return td_punishedDao.countByFd_punishedId(loginId);
    }

    @Override
    public List<Object[]> getByloginId(int loginId, int page) {
        return td_punishedDao.getByloginId(loginId,PageRequest.of(page,10));
    }
}
